/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.admanager.soageneralpattern.plugin.soageneralpattern.impl;

import java.util.Collection;

import org.admanager.soageneralpattern.plugin.soageneralpattern.Element;
import org.admanager.soageneralpattern.plugin.soageneralpattern.Multiplicity;
import org.admanager.soageneralpattern.plugin.soageneralpattern.Pattern;
import org.admanager.soageneralpattern.plugin.soageneralpattern.Role;
import org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Pattern</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.admanager.soageneralpattern.plugin.soageneralpattern.impl.PatternImpl#getElements <em>Elements</em>}</li>
 *   <li>{@link org.admanager.soageneralpattern.plugin.soageneralpattern.impl.PatternImpl#getMultiplicities <em>Multiplicities</em>}</li>
 *   <li>{@link org.admanager.soageneralpattern.plugin.soageneralpattern.impl.PatternImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.admanager.soageneralpattern.plugin.soageneralpattern.impl.PatternImpl#getContainingRoles <em>Containing Roles</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PatternImpl extends EObjectImpl implements Pattern {
	/**
	 * The cached value of the '{@link #getElements() <em>Elements</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElements()
	 * @generated
	 * @ordered
	 */
	protected EList elements;

	/**
	 * The cached value of the '{@link #getMultiplicities() <em>Multiplicities</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMultiplicities()
	 * @generated
	 * @ordered
	 */
	protected EList multiplicities;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getContainingRoles() <em>Containing Roles</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getContainingRoles()
	 * @generated
	 * @ordered
	 */
	protected EList containingRoles;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PatternImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return soageneralpatternPackage.Literals.PATTERN;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getElements() {
		if (elements == null) {
			elements = new EObjectContainmentEList(Element.class, this, soageneralpatternPackage.PATTERN__ELEMENTS);
		}
		return elements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getMultiplicities() {
		if (multiplicities == null) {
			multiplicities = new EObjectContainmentEList(Multiplicity.class, this, soageneralpatternPackage.PATTERN__MULTIPLICITIES);
		}
		return multiplicities;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, soageneralpatternPackage.PATTERN__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getContainingRoles() {
		if (containingRoles == null) {
			containingRoles = new EObjectContainmentEList(Role.class, this, soageneralpatternPackage.PATTERN__CONTAINING_ROLES);
		}
		return containingRoles;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case soageneralpatternPackage.PATTERN__ELEMENTS:
				return ((InternalEList)getElements()).basicRemove(otherEnd, msgs);
			case soageneralpatternPackage.PATTERN__MULTIPLICITIES:
				return ((InternalEList)getMultiplicities()).basicRemove(otherEnd, msgs);
			case soageneralpatternPackage.PATTERN__CONTAINING_ROLES:
				return ((InternalEList)getContainingRoles()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case soageneralpatternPackage.PATTERN__ELEMENTS:
				return getElements();
			case soageneralpatternPackage.PATTERN__MULTIPLICITIES:
				return getMultiplicities();
			case soageneralpatternPackage.PATTERN__NAME:
				return getName();
			case soageneralpatternPackage.PATTERN__CONTAINING_ROLES:
				return getContainingRoles();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case soageneralpatternPackage.PATTERN__ELEMENTS:
				getElements().clear();
				getElements().addAll((Collection)newValue);
				return;
			case soageneralpatternPackage.PATTERN__MULTIPLICITIES:
				getMultiplicities().clear();
				getMultiplicities().addAll((Collection)newValue);
				return;
			case soageneralpatternPackage.PATTERN__NAME:
				setName((String)newValue);
				return;
			case soageneralpatternPackage.PATTERN__CONTAINING_ROLES:
				getContainingRoles().clear();
				getContainingRoles().addAll((Collection)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
			case soageneralpatternPackage.PATTERN__ELEMENTS:
				getElements().clear();
				return;
			case soageneralpatternPackage.PATTERN__MULTIPLICITIES:
				getMultiplicities().clear();
				return;
			case soageneralpatternPackage.PATTERN__NAME:
				setName(NAME_EDEFAULT);
				return;
			case soageneralpatternPackage.PATTERN__CONTAINING_ROLES:
				getContainingRoles().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case soageneralpatternPackage.PATTERN__ELEMENTS:
				return elements != null && !elements.isEmpty();
			case soageneralpatternPackage.PATTERN__MULTIPLICITIES:
				return multiplicities != null && !multiplicities.isEmpty();
			case soageneralpatternPackage.PATTERN__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case soageneralpatternPackage.PATTERN__CONTAINING_ROLES:
				return containingRoles != null && !containingRoles.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //PatternImpl
